import { observable, action } from 'mobx';
import * as Api from '../../apis/setting/setting';

import AccountStore from './Account';
import ConventionalStore from './Conventional';
import TemplateStore from './Template';
import SignStore from './Sign';
import RuleStore from './Rule';
import LabelStore from './Label';
import FolderStore from './Folder';
import AutoRespondStore from './AutoRespond';
import BlackListStore from './BlackList';
import AutoClearRuleStore from './AutoClearRule';

const initalState = {
  topDatas: [],
  // selectedKey: '',
  rightMenuDatas: [],
  loading: false,
};
export default class SettingStore {
  @observable topDatas = initalState.topDatas; // 选项卡
  // @observable selectedKey = initalState.selectedKey;  // 选中Tab--when component unMounted need to clear selectedKey's data, use this
  @observable selectedKey = ''; // 选中Tab
  @observable rightMenuDatas = initalState.rightMenuDatas; // 右键菜单选项
  @observable loading = initalState.loading; // 邮件设置需要用到的WeaTop~Loading状态

  // there are emailSetting pages use store, put them there out of clear search
  @observable accountStore = new AccountStore();
  @observable conventionalStore = new ConventionalStore();
  @observable templateStore = new TemplateStore();
  @observable signStore = new SignStore();
  @observable ruleStore = new RuleStore();
  @observable labelStore = new LabelStore();
  @observable folderStore = new FolderStore();
  @observable autoRespondStore = new AutoRespondStore();
  @observable blackListStore = new BlackListStore();
  @observable autoClearRuleStore = new AutoClearRuleStore();


  @action setStoreState = (params) => {
    Object.keys(params).forEach((key) => {
      this[key] = params[key];
    });
  }

  @action clear = () => this.setStoreState(initalState);

  @action getMailSetTabs = async (params) => { // request title
    let res = await Api.getMailSetTabs(params);
    return res;
  }
}
